home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / misc / rpdos4g2.zip / RPDOS4GP.C < prev    next >
C/C++ Source or Header  |  1994-11-23  |  3KB  |  83 lines

  1. /*  WARNING! EXTREMELY MESSY AND UNOPTIMAL C CODE! READ AT YOUR OWN RISK!
  2.  
  3.     The following mess of code is designed to rip apart an EXE which was
  4.     previously compiled using Watcom C/C++ & DOS/4G Professional and replace
  5.     the old stub with PMODEW.EXE, thus making it a self contained EXE.
  6.  
  7.     This program doesn't do much error checking, so if it doesn't work it is
  8.     pretty much your problem. It is assumed there is enough available memory
  9.     to be able to read in your file + PMODEW.EXE
  10.  
  11.     Originally Written For WATCOM C/C++ version 10
  12.  
  13.     USE THIS PROGRAM AT YOUR OWN RISK... NOBODY CARES WHAT HAPPENS!
  14. */
  15.  
  16. #include <stdio.h>
  17. #include <io.h>
  18.  
  19. FILE *fp1,*fp2,*fp3;
  20. char *ptr1,*ptr2;
  21. unsigned int x,y,z,handle1,handle2;
  22. unsigned int length1,length2;
  23.  
  24. main(int argc,char *argv[]){
  25. if((fp1=fopen(argv[1],"rb"))==NULL) {printf("Use me like this - RPDOS4GP <filename>\n"); exit(1);}
  26. if((fp2=fopen("pmodew.exe","rb"))==NULL) {printf("Unable To Open PMODEW.EXE!\n"); exit(1);}
  27. handle1=fileno(fp1);
  28. handle2=fileno(fp2);
  29. length1=filelength(handle1);
  30. length2=filelength(handle2);
  31. if((ptr1=(char *)malloc(length1))==NULL) {printf("Error Allocating %u Bytes Of Memory!\n",length1); exit(1);}
  32. if((ptr2=(char *)malloc(length2))==NULL) {printf("Error Allocating %u Bytes Of Memory!\n",length2); exit(1);}
  33. printf("- Searching For DOS/4G Headers\n");
  34. fread(ptr1,0x20,1,fp1);
  35. x=*(unsigned short int *)(ptr1+4)*512;
  36. y=*(unsigned short int *)(ptr1+2);
  37. if(y!=0) x=(x-512)+y;
  38. fseek(fp1,x,0);
  39. fread(ptr1,0x30,1,fp1);
  40. if(ptr1[0]!='B' || ptr1[1]!='W') {printf("Error Removing DOS/4G Header!\n"); exit(1);}
  41. y=*(unsigned int *)(ptr1+0x20);
  42. fseek(fp1,x+y,0);
  43. length1-=ftell(fp1);
  44. printf("- Reading %s\n",argv[1]);
  45. fread(ptr1,length1,1,fp1);
  46. printf("- Reading PMODEW.EXE\n");
  47. fread(ptr2,length2,1,fp2);
  48. if((fp3=fopen("NEW.EXE","wb+"))==NULL) {printf("Error Opening Temp File!\n"); exit(1);}
  49. printf("- Writing New EXE Header\n");
  50. *(unsigned short int *)(ptr2+0x20+19)=0xFFFF;
  51. fwrite(ptr2,2,1,fp3);
  52. x=*(unsigned short int *)(ptr2+2);
  53. y=*(unsigned short int *)(ptr2+4);
  54. if(x<512-0x21) x+=0x20;
  55. else {y++; x=(x+0x20)-512;}
  56. *(unsigned short int *)(ptr2+2)=x;
  57. *(unsigned short int *)(ptr2+4)=y;
  58. fwrite(ptr2+2,6,1,fp3);
  59. fputc(4,fp3);
  60. fputc(0,fp3);
  61. fwrite(ptr2+10,14,1,fp3);
  62. fputc(0x40,fp3);
  63. fputc(0,fp3);
  64. for(x=0;x<34;x++) fputc(0,fp3);
  65.  
  66. x=length2+0x20;
  67. if((x&0x0FFF)!=0) x+=(0x1000-x&0x0FFF);
  68. x+=(0x0FFF)&(*(unsigned int *)(ptr1+0x3c));
  69.  
  70. fwrite(&x,4,1,fp3);
  71. fwrite(ptr2+0x20,length2-0x20,1,fp3);
  72. if((x-length2+0x20)!=0) for(y=0;y<x-(length2+0x20);y++) fputc(0,fp3);
  73. y=*(unsigned int *)(ptr1+0x3c);
  74. z=*(unsigned int *)(ptr1+y+0x80);
  75. z+=(x-y)&0xF000;
  76. *(unsigned int *)(ptr1+y+0x80)=z;
  77. printf("- Writing Executable Data\n");
  78. fwrite(ptr1+y,length1-y,1,fp3);
  79. fcloseall();
  80. printf("- Done!\n");
  81. return 0;
  82. }
  83.